import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt
from pandas_datareader import wb
sns.set(style = "whitegrid", rc = {"figure.figsize": (10, 8)})
eu_countries = ['BE', 'BG', 'CZ', 'DK', 'DE', 'EE', 'IE', 'GR', 'ES', 'FR', 'HR',
'IT', 'CY', 'LV', 'LT', 'LU', 'HU', 'MT', 'NL', 'AT', 'PL', 'PT',
'RO', 'SI', 'SK', 'FI', 'SE', 'GB']
ue = wb.download(indicator = "SL.UEM.TOTL.ZS",
country = eu_countries, start = 1991,
end = 2019)
ue.reset_index(inplace = True)
ue.columns = ['country', 'year', 'unemployment']seabornseaborn’s heatmap() function; takes a wide data frame with x-values in the index and y-values as column headersseaborn ‘heat map’seabornseaborn; available in the color_palette() functionseabornmx = pd.read_csv('http://personal.tcu.edu/kylewalker/mexico.csv')
sns.barplot(x = 'gdp08', y = 'name',
data = mx.sort_values('gdp08', ascending = False),
palette = "Greens_r")# Convert the year to integer for better labels
ue["year"] = ue["year"].astype(int)
# Make a Greece-only dataset
greece = ue[ue.country == "Greece"]
# Plot everything as grey, first
sns.lineplot(data = ue, x = "year", y = "unemployment",
hue = "country", palette = ["grey"] * 28,
legend = False)
# Then, plot Greece on top
sns.lineplot(data = greece, x = "year", y = "unemployment",
hue = "country", palette = ["blue"], linewidth = 3)seaborn is a wrapper around matplotlib, the main plotting engine for Pythonmatplotlib customization methods are available for your seaborn plots - and there are many!import matplotlib.pyplot as pltseaborn and matplotlibseaborn returns a matplotlib object that can be modified by the options in the pyplot moduleseaborn and available as arguments - so check the documentation to see what you can do!